The following is the code.
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity implements OnClickListener{
EditText e1,e2,e3;
Button b1;
double d1,d2,d3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1=(Button)findViewById(R.id.b2);
e1=(EditText)findViewById(R.id.e1);
e2=(EditText)findViewById(R.id.e2);
e3=(EditText)findViewById(R.id.e3);
b1.setOnClickListener(this);
}
public void onClick(View v) {
// TODO Auto-generated method stub
d1=Double.parseDouble(e1.getText().toString());
d2=Double.parseDouble(e2.getText().toString());
d3=d1+d2;
e3.setText(Double.toString(d3));
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/hydrangeas"
android:orientation="vertical"
>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FN"/>
<EditText android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/e1"
android:hint="Enter First Number"/>
</LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SN"/>
<EditText android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/e2"
android:hint="Enter Second Number"/>
</LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Result"/>
<EditText android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/e3"
android:hint="Result is here"/>
</LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/b2"
android:text="Click here to add"/>
</LinearLayout>
</LinearLayout>